package com.grass.p019lv.adapter;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.androidx.p013lv.base.bean.VideoBean;
import com.androidx.p013lv.base.glide.GlideUtils;
import com.androidx.p013lv.base.recycler.BaseRecyclerAdapter;
import com.androidx.p013lv.base.recycler.BaseRecyclerHolder;
import com.androidx.p013lv.base.utils.TimeUtils;
import com.androidx.p013lv.base.utils.UiUtils;
import com.grass.p019lv.R;
import com.grass.p019lv.bean.DownloadVideoBean;
import java.util.ArrayList;

import jaygoo.library.m3u8downloader.bean.M3U8Task;

/* renamed from: com.grass.lv.adapter.MineDownLoadVideoAdapter */
public class MineDownLoadVideoAdapter extends BaseRecyclerAdapter<DownloadVideoBean, MineDownLoadVideoAdapter.Holder> {
    private String domain;

    public void setDomain(String str) {
        this.domain = str;
    }

    public void MyHolder(Holder holder, int i) {
        holder.setData((DownloadVideoBean) getDataInPosition(i));
    }

    @Override // androidx.recyclerview.widget.RecyclerView.Adapter
    public Holder onCreateViewHolder(ViewGroup viewGroup, int i) {
        return new Holder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_mine_down_load_video, viewGroup, false));
    }

    /* access modifiers changed from: package-private */
    /* renamed from: com.grass.lv.adapter.MineDownLoadVideoAdapter$Holder */
    public class Holder extends BaseRecyclerHolder {
        ImageView img_select;
        ImageView iv_cover;
        ImageView iv_download_status = ((ImageView) this.itemView.findViewById(R.id.iv_download_status));
        ImageView iv_original = ((ImageView) this.itemView.findViewById(R.id.iv_original));
        ImageView iv_vip = ((ImageView) this.itemView.findViewById(R.id.iv_vip));
        LinearLayout ll_download_status = ((LinearLayout) this.itemView.findViewById(R.id.ll_download_status));
        TextView tv_collect;
        TextView tv_download_progress = ((TextView) this.itemView.findViewById(R.id.tv_download_progress));
        TextView tv_download_status = ((TextView) this.itemView.findViewById(R.id.tv_download_status));
        TextView tv_pay = ((TextView) this.itemView.findViewById(R.id.tv_pay));
        TextView tv_score;
        TextView tv_sub_title;
        TextView tv_time;
        TextView tv_title;

        Holder(View view) {
            super(view);
            this.iv_cover = (ImageView) view.findViewById(R.id.iv_cover);
            this.img_select = (ImageView) view.findViewById(R.id.img_select);
            this.tv_score = (TextView) view.findViewById(R.id.tv_score);
            this.tv_time = (TextView) view.findViewById(R.id.tv_time);
            this.tv_title = (TextView) view.findViewById(R.id.tv_title);
            this.tv_sub_title = (TextView) view.findViewById(R.id.tv_sub_title);
            this.tv_collect = (TextView) view.findViewById(R.id.tv_collect);
        }

        /* access modifiers changed from: package-private */
        public void setData(DownloadVideoBean downloadVideoBean) {
            VideoBean videoBean = downloadVideoBean.getVideoBean();
            if (downloadVideoBean.getEditState() == 0) {
                this.ll_download_status.setVisibility(View.VISIBLE);
                this.img_select.setVisibility(View.GONE);
            } else if (downloadVideoBean.getEditState() == 1) {
                this.img_select.setImageResource(R.drawable.mine_btn_edit_un_select);
                this.img_select.setVisibility(View.VISIBLE);
                this.ll_download_status.setVisibility(View.GONE);
            } else {
                this.img_select.setImageResource(R.drawable.mine_btn_edit_select);
                this.img_select.setVisibility(View.VISIBLE);
                this.ll_download_status.setVisibility(View.GONE);
            }
            if (videoBean != null) {
                if (!TextUtils.isEmpty(videoBean.getCoverImg().get(0))) {
                    GlideUtils.loadCropRadius(MineDownLoadVideoAdapter.this.domain + videoBean.getCoverImg().get(0), 10, this.iv_cover);
                } else {
                    GlideUtils.loadCropRadiusDefault(10, this.iv_cover);
                }
                this.tv_time.setText(TimeUtils.stringForTime(videoBean.getPlayTime() * 1000));
                this.tv_title.setText(videoBean.getTitle());
                this.tv_sub_title.setVisibility(View.GONE);
                this.iv_vip.setVisibility(View.GONE);
                this.tv_pay.setVisibility(View.GONE);
                if (videoBean.getVideoType() == 1) {
                    this.iv_vip.setVisibility(View.VISIBLE);
                } else if (videoBean.getVideoType() == 2) {
                    this.tv_pay.setVisibility(View.VISIBLE);
                }
                TextView textView = this.tv_score;
                textView.setText(UiUtils.num2str(videoBean.getFakeWatchNum()) + "");
            }
            MineDownLoadVideoAdapter.this.setProgressText(this.tv_download_progress, this.tv_download_status, this.iv_download_status, downloadVideoBean.getM3U8Task());
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void setProgressText(TextView textView, TextView textView2, ImageView imageView, M3U8Task m3U8Task) {
        imageView.setImageResource(0);
        switch (m3U8Task.getState()) {
            case -1:
                textView2.setText("等待中");
                textView2.setTextColor(UiUtils.getResources().getColor(R.color.download_downloading));
                textView.setVisibility(View.GONE);
                textView.setText("(" + String.format("%.2f", Float.valueOf(m3U8Task.getProgress() * 100.0f)) + "%)");
                imageView.setImageResource(R.drawable.ic_download_downloading);
                return;
            case 0:
            default:
                textView.setVisibility(View.GONE);
                textView.setText("");
                textView2.setText("暫停中");
                textView2.setTextColor(UiUtils.getResources().getColor(R.color.download_pause));
                imageView.setImageResource(R.drawable.ic_download_pause);
                return;
            case 1:
                textView2.setText("下載中");
                textView2.setTextColor(UiUtils.getResources().getColor(R.color.download_downloading));
                imageView.setImageResource(R.drawable.ic_download_downloading);
                return;
            case 2:
                textView2.setText("下載中(" + String.format("%.2f", Float.valueOf(m3U8Task.getProgress() * 100.0f)) + "%)");
                textView2.setTextColor(UiUtils.getResources().getColor(R.color.download_downloading));
                imageView.setImageResource(R.drawable.ic_download_downloading);
                return;
            case 3:
                textView2.setText("下載完成");
                textView2.setTextColor(UiUtils.getResources().getColor(R.color.download_success));
                textView.setVisibility(View.GONE);
                textView.setText("");
                imageView.setImageResource(R.drawable.ic_download_success);
                return;
            case 4:
                return;
            case 5:
                textView.setVisibility(View.GONE);
                textView.setText("");
                textView2.setText("暫停中");
                textView2.setTextColor(UiUtils.getResources().getColor(R.color.download_pause));
                imageView.setImageResource(R.drawable.ic_download_pause);
                return;
            case 6:
                textView.setVisibility(View.GONE);
                textView.setText("");
                textView2.setText("存儲空間不足");
                textView2.setTextColor(UiUtils.getResources().getColor(R.color.download_pause));
                imageView.setImageResource(R.drawable.ic_download_pause);
                return;
        }
    }

    public void notifyChanged(ArrayList<DownloadVideoBean> arrayList, M3U8Task m3U8Task) {
        if (arrayList != null && arrayList.size() > 0) {
            for (int i = 0; i < getItemCount(); i++) {
                if (((DownloadVideoBean) getDataInPosition(i)).getM3U8Task().getUrl().equals(m3U8Task.getUrl())) {
                    arrayList.get(i).setM3U8Task(m3U8Task);
                    setData(arrayList);
                    notifyDataSetChanged();
                }
            }
        }
    }
}
